package pdn.scs.json;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pdn.scs.core.Student;

import com.google.gson.Gson;

@WebServlet("/StudentListServlet")
public class StudentListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public StudentListServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json");
		PrintWriter out = response.getWriter();

		Student s1 = new Student("Kanchana", "S/11/121", "Physical");
		Student s2 = new Student("Anjana", "S/11/122", "Bio");
		Student s3 = new Student("Thushara", "S/11/123", "Physical");

		List<Student> list = new ArrayList<Student>();
		list.add(s1);
		list.add(s2);
		list.add(s3);
		
		Gson gson = new Gson();
		out.print(gson.toJson(list));
		out.flush();
	}

}
